package it.storm.solution;

import java.util.ArrayList;
import java.util.List;

/**
 * 1800. 最大升序子数组和
 * https://leetcode-cn.com/problems/maximum-ascending-subarray-sum/
 */
public class Solutions_1800 {
    public static void main(String[] args) {
        int[] nums1 = {10, 20, 30, 5, 10, 50};  // output: 65
        int[] nums2 = {10, 20, 30, 40, 50};  // output: 150
        int[] nums3 = {12, 17, 15, 13, 10, 11, 12};  // output: 33
        int[] nums4 = {100, 10, 1};  // output: 100

        List<int[]> inputs = new ArrayList<>();
        inputs.add(nums1);
        inputs.add(nums2);
        inputs.add(nums3);
        inputs.add(nums4);

        for (int[] input : inputs) {
            int result = maxAscendingSum(input);
            System.out.println(result);
        }
    }

    public static int maxAscendingSum(int[] nums) {
        if (nums == null) {
            return 0;
        }
        int cur = nums[0], res = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                cur += nums[i];
            } else {
                res = Math.max(res, cur);
                cur = nums[i];
            }
        }
        return Math.max(res, cur);
    }
}
